package com.java.poc.iofile;

import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileReader;
import java.io.IOException;

public class BufferedInputStreamExample {
	public static void main(String[] args) {

		File file = new File("C:\\testing.txt");
		FileInputStream fis = null;
		BufferedInputStream bis = null;
		DataInputStream dis = null;
		BufferedReader br = null;

		try {
			fis = new FileInputStream(file);

			bis = new BufferedInputStream(fis);
			dis = new DataInputStream(bis);
			br = new BufferedReader(new FileReader(file));

			while (dis.available() != 0) {
				System.out.println(dis.readLine());
			}

			String str = null;
			while ((str = br.readLine()) != null) {
				System.out.println(str);
			}

		} catch (IOException e) {
			e.printStackTrace();
		} finally {
			try {
				fis.close();
				bis.close();
				dis.close();
				br.close();
			} catch (IOException ex) {
				ex.printStackTrace();
			}
		}


		try (BufferedReader br1 = new BufferedReader(new FileReader("C:\\testing.txt")))
		{

			String sCurrentLine;

			while ((sCurrentLine = br1.readLine()) != null) {
				System.out.println(sCurrentLine);
			}

		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}
